package com.wiretrack.circuit;

import java.io.File;

import org.apache.log4j.Logger;

public class Sound
{
	private static Logger log = Logger.getLogger(Sound.class.getName());
	public String refid;
	public int playAt;
	
	public String getResolvedRef(Configuration config)
	{
		String retVal = refid;
		boolean hit = false;
		for (SoundFile soundFile : config.soundFiles.soundFiles)
		{
			if(refid.equals(soundFile.id))
			{
				hit = true;
				log.debug("returning file: " + config.soundFiles.root + File.separator + soundFile.name);
				retVal = config.soundFiles.root + File.separator + soundFile.name;
				break;
			}
		}
		
		if(!hit)
		{
			log.warn("No sound id found for refid: " + refid + " - so not playing any sound");
		}
		
		return retVal;
	}
	
	public String toString()
	{
		StringBuilder buf = new StringBuilder();
		
		buf.append("{ref=" + refid);
		buf.append(" playAt=" + playAt + "}");
		
		return buf.toString();
	}
}
